home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 26 / Cream of the Crop 26.iso / program / ddj0897.zip / ISERVER.ZIP / MFCISAPI.ZIP / CBISAPI.CPP < prev    next >
C/C++ Source or Header  |  1997-01-03  |  4KB  |  153 lines

  1. // cbisapi.cpp : Defines the initialization routines for the DLL.
  2. //
  3.  
  4. #include "stdafx.h"
  5. #include "cbisapi.h"
  6. #include "IServer.h"
  7. #include <malloc.h>
  8. #include <afxconv.h>
  9.  
  10. #ifdef _DEBUG
  11. #define new DEBUG_NEW
  12. #undef THIS_FILE
  13. static char THIS_FILE[] = __FILE__;
  14. #endif
  15.  
  16. /////////////////////////////////////////////////////////////////////////////
  17. // CCbisapiApp
  18.  
  19. BEGIN_MESSAGE_MAP(CCbisapiApp, CWinApp)
  20.     //{{AFX_MSG_MAP(CCbisapiApp)
  21.         // NOTE - the ClassWizard will add and remove mapping macros here.
  22.         //    DO NOT EDIT what you see in these blocks of generated code!
  23.     //}}AFX_MSG_MAP
  24. END_MESSAGE_MAP()
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CCbisapiApp construction
  28.  
  29. CCbisapiApp::CCbisapiApp()
  30. {
  31.     // TODO: add construction code here,
  32.     // Place all significant initialization in InitInstance
  33. }
  34.  
  35. /////////////////////////////////////////////////////////////////////////////
  36. // The one and only CCbisapiApp object
  37.  
  38. CCbisapiApp theApp;
  39.  
  40. /////////////////////////////////////////////////////////////////////////////
  41. // CCbisapiApp initialization
  42.  
  43. BOOL CCbisapiApp::InitInstance()
  44. {
  45.     // Register all OLE server (factories) as running.  This enables the
  46.     //  OLE libraries to create objects from other applications.
  47.     COleObjectFactory::RegisterAll();
  48.     return TRUE;
  49. }
  50.  
  51. /////////////////////////////////////////////////////////////////////////////
  52. // Special entry points required for inproc servers
  53.  
  54. STDAPI DllGetClassObject(REFCLSID rclsid, REFIID riid, LPVOID* ppv)
  55. {
  56.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  57.     return AfxDllGetClassObject(rclsid, riid, ppv);
  58. }
  59.  
  60. STDAPI DllCanUnloadNow(void)
  61. {
  62.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  63.     return AfxDllCanUnloadNow();
  64. }
  65.  
  66. // by exporting DllRegisterServer, you can use regsvr.exe
  67. STDAPI DllRegisterServer(void)
  68. {
  69.     AFX_MANAGE_STATE(AfxGetStaticModuleState());
  70.     COleObjectFactory::UpdateRegistryAll();
  71.     return S_OK;
  72. }
  73.  
  74. // ISAPI Functions
  75.  BOOL WINAPI GetExtensionVersion (HSE_VERSION_INFO *pVer)
  76.     {
  77.     pVer->dwExtensionVersion=MAKELONG(HSE_VERSION_MINOR,HSE_VERSION_MAJOR);
  78.     lstrcpyn(pVer->lpszExtensionDesc,
  79.         "OLE object ISAPI Gateway. Copyright 1997 by Al Williams",
  80.         HSE_MAX_EXT_DLL_NAME_LEN);
  81.     return TRUE;
  82.     }
  83.  
  84.  DWORD WINAPI HttpExtensionProc(EXTENSION_CONTROL_BLOCK *lpEcb)
  85.     {
  86.     // create IsapiServer object
  87.     USES_CONVERSION;
  88.     CoInitialize(NULL);
  89.     CIsapiServer svr;
  90.     svr.SetECB(lpEcb);
  91.     // create user's object
  92.     COleDispatchDriver obj;
  93.     COleException x;
  94.     DWORD siz;
  95.     CString str;
  96.     OLECHAR *name;
  97.     char *plus,*colon;
  98.     colon=strchr(lpEcb->lpszQueryString,':');
  99.     plus=strchr(lpEcb->lpszQueryString,'+');
  100.     if (plus) *plus='\0';
  101.     if (colon) 
  102.         {
  103.         *colon='\0';
  104.         name=A2W(colon+1);
  105.         }
  106.     else
  107.         name=L"ISAPI";
  108.     if (!obj.CreateDispatch(lpEcb->lpszQueryString,&x))
  109.         {
  110.         str.Format("Can't create %s %x",lpEcb->lpszQueryString,x.m_sc);
  111.         siz=str.GetLength();
  112.         lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
  113.         return HSE_STATUS_SUCCESS;
  114.         }
  115.     if (plus) *plus='+';
  116.     *colon=':';
  117.     // call user's object ISAPI method passing IsapiServer object
  118.     DISPID dispid;
  119.     static BYTE params[]= VTS_DISPATCH;
  120.     IDispatch * dsptch=svr.GetIDispatch(FALSE);
  121.     if (FAILED(obj.m_lpDispatch->GetIDsOfNames(IID_NULL,&name,1, LOCALE_SYSTEM_DEFAULT,&dispid)))
  122.         {
  123.         str.Format("Can't find method %s",colon?colon+1:"ISAPI");
  124.         siz=str.GetLength();
  125.         lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
  126.         return HSE_STATUS_SUCCESS;
  127.         }
  128.     try 
  129.         {
  130.         obj.InvokeHelper(dispid,DISPATCH_METHOD,VT_EMPTY,NULL,params,dsptch);
  131.         }
  132.     catch (COleException *e)
  133.         {
  134.         str.Format("COleException: &H%x",    e->m_sc);
  135.         siz=str.GetLength();
  136.         lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
  137.         }
  138.     catch (COleDispatchException *e)
  139.         {
  140.         str.Format("COleDispatchException: %s",    e->m_strDescription);
  141.         siz=str.GetLength();
  142.         lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
  143.         }
  144.     catch (...)
  145.         {
  146.         str.Format("Unknown Exception!");
  147.         siz=str.GetLength();
  148.         lpEcb->WriteClient(lpEcb->ConnID,(LPVOID)(LPCSTR)str,&siz,0);
  149.         }
  150.     // return status
  151.     CoUninitialize();
  152.     return svr.GetRV(); // init
  153.     }